import { RequestMethod } from "../lib/defines";
import { MemberBase, RoomBase } from "../utils/types";
import { ChatModeEnums } from "../utils/enums";

export type CreateQuery = {
  type: ChatModeEnums;
  /**
   * 所属用户
   */
  member: MemberBase;

  /**
   * 所属房间
   */
  room: RoomBase;
}

/**
 * 强拆
 *
 * @param app
 */
export default function forciblyBreakUp (app) {
  const { socket } = app.locals;
  // const { userId } = socket.handshake.query;
  socket.on(RequestMethod.forciblyBreakUp, function createClassroom (data: CreateQuery, cb) {
    const { room } = data;
    const { rooms } = app.locals;
    const members = rooms[room.classId].getMembers();
    const member = members[0]

    socket.to(room.classId).emit('breakUp');
    socket.to(member.userId).disconnect();
  });
}
